﻿/// <reference path="Common.ts" /> 
/// <reference path="Enum.ts" />


// #region  枚举处理
class ComboxItem {
    id: number;
    text: string
}

class EnumEx {
    static getNames(e: any): Array<string> {
        var a: Array<string> = [];
        for (var val in e) {
            if (isNaN(val)) {
                a.push(val);
            }
        }
        return a;
    }

    static getValues(e: any): Array<number> {
        var a: Array<number> = [];
        for (var val in e) {
            if (!isNaN(val)) {
                a.push(parseInt(val, 10));
            }
        }
        return a;
    }

    static getDicts(e: any, b: Common.Func<number,boolean>): Array<ComboxItem> {
        var data: Array<ComboxItem> = [];
        for (var val in e) {
            if (!isNaN(val)) {
                var id = Number(val);
                if (b(id))
                {
                    var item: ComboxItem = new ComboxItem();
                    item.id = id;
                    item.text = formatEnum(id);
                    data.push(item);
                }
            }
        }
        return data;
    }
}
//#endregion

// #region  业务处理
class Bussiness {
    /**
     * 计算技术等级
     * @param sttype：结构类型
     * @param length：结构长度
     */
    public calcTeachClass = (sttype: number, length: number): ComboxItem=>
    {
        if (!sttype || !length) return null;
        if (length < 1) return null;

        var item: ComboxItem = new ComboxItem();
        if (sttype == SturctureEnum.B111) {
            if (length > 1000) {
                item.id = BridgeTechnicalEnum.B141;
            }
            else if (length >= 100) {
                item.id = BridgeTechnicalEnum.B142;
            }
            else if (length > 30) {
                item.id = BridgeTechnicalEnum.B143;
            }
            else if (length > 0) {
                item.id = BridgeTechnicalEnum.B144;
            }
        }
        else if (sttype == SturctureEnum.T120) {
            if (length > 3000) {
                item.id = TunnelTechnicalEnum.T146;
            }
            else if (length > 1000) {
                item.id = TunnelTechnicalEnum.T147;
            }
            else if (length > 500) {
                item.id = TunnelTechnicalEnum.T148;
            }
            else if (length > 0) {
                item.id = TunnelTechnicalEnum.T149;
            }
        } else {
            return null;
        }
            
        item.text = formatEnum(item.id);
        return item;
    }


     /**
     * 加载行车方向
     * @param b：是否全幅
     */
    public getDirectData = (b: boolean): ComboxItem[]=> {
        var data: ComboxItem[] = [];
        if (b) {
            var item: ComboxItem = new ComboxItem();
            item.id = DirectionEnum.All13;
            item.text = formatEnum(item.id);
            data.push(item);
        }
        else
        {
            var item: ComboxItem = new ComboxItem();
            item.id = DirectionEnum.Up11;
            item.text = formatEnum(item.id);
            data.push(item);

            var item1: ComboxItem = new ComboxItem();
            item1.id = DirectionEnum.Down12;
            item1.text = formatEnum(item1.id);
            data.push(item1);
        }
        return data;
    }  

}
//#endregion